package com.briup.web.controller;

import com.briup.pojo.Customer;
import com.briup.pojo.response.Result;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author pgc
 * @Description:
 * @date 2024/11/6 11:14
 */
@RestController
public class SessionController {

    @GetMapping("login3")
    public Result login3(HttpServletRequest request){
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        Customer customer = new Customer();
        customer.setName(name);
        customer.setPassword(password);
        HttpSession session = request.getSession();
        System.out.println(session);
        session.setAttribute("customer",customer);
        return Result.success();
    }

    @GetMapping("getSession1")
    public Result  getSession1(HttpServletRequest request){
        HttpSession session = request.getSession(false);
        System.out.println("获取:"+session);
        Customer customer= (Customer) session.getAttribute("customer");
        System.out.println(customer);
            return Result.success();
    }
}
